package svc

import (
	"gorm.io/gorm"
	"iot-base/auth/db"
	"iot-base/auth/model"
	"iot-base/auth/model/iot"
)

var Dao *ServiceContext

func (s *ServiceContext) GetDb() *gorm.DB {
	return db.Db
}
func init() {
	Dao = NewServiceContext(db.Db)
}

type ServiceContext struct {
	TUser              model.UserMode
	TAuthGroup         model.AuthGroupModel
	TAuthGroupStation  model.AuthGroupStationsModel
	TAuthRole          model.AuthRoleModel
	TAuthRule          model.AuthRuleModel
	TCompany           model.CompanyMode
	TOperationLog      model.OperationLogsModel
	TPresets           model.PresetModel
	TUserGroup         model.UserGroupModel
	TUserRole          model.UserRoleMode
	TTasks             model.TasksModel
	TTaskLog           model.TaskLogMoodle
	TTaskLogDetail     model.TaskLogDetailMoodle
	TAlarm             iot.AlarmMode
	TAlarmHistory      iot.AlarmHistoryModel
	TStations          iot.StationMode
	TThingStation      iot.ThingStationModel
	TThings            iot.ThingModel
	TTModel            iot.TModelModel
	TThingParams       iot.ThingParamsModel
	TEvent             iot.EventMode
	THisData           iot.HisDataModel
	TGateRule          model.GateRuleMode
	TProtocol          iot.ProtocolMode
	TThingMaintainInfo iot.ThingMaintainInfoModel
	TCatalog           iot.CatalogMode
	TAreas             iot.AreasMode
}

func NewServiceContext(db *gorm.DB) *ServiceContext {
	return &ServiceContext{
		TUser:              *model.NewUserMode(db),
		TAuthGroup:         *model.NewAuthGroupModel(db),
		TAuthGroupStation:  *model.NewAuthGroupStationsModel(db),
		TAuthRole:          *model.NewAuthRoleModel(db),
		TAuthRule:          *model.NewAuthRuleModel(db),
		TCompany:           *model.NewCompanyMode(db),
		TOperationLog:      *model.NewOperationLogsModel(db),
		TPresets:           *model.NewPresetModel(db),
		TUserGroup:         *model.NewUserGroupMode(db),
		TUserRole:          *model.NewUserRoleMode(db),
		TTasks:             *model.NewTasksModel(db),
		TTaskLog:           *model.NewTaskLogMoodle(db),
		TTaskLogDetail:     *model.NewTaskLogDetailMoodle(db),
		TGateRule:          *model.NewGateRule(db),
		TAlarm:             *iot.NewAlarmMode(db),
		TAlarmHistory:      *iot.NewAlarmHistroyModel(db),
		TStations:          *iot.NewStationMode(db),
		TThingStation:      *iot.NewThingStationModel(db),
		TThings:            *iot.NewThingModel(db),
		TTModel:            *iot.NewTModelModel(db),
		TThingParams:       *iot.NewThingParamsModel(db),
		TEvent:             *iot.NewEventMode(db),
		THisData:           *iot.HisDataNew(db),
		TProtocol:          *iot.NewProtocolMode(db),
		TThingMaintainInfo: *iot.NewThingMaintainInfoModel(db),
		TCatalog:           *iot.NewCatalogMode(db),
		TAreas:             *iot.NewAreasMode(db),
	}
}
